package com.sinosoft.dsp.platform.components.portal.iteration;

import com.sinosoft.dsp.system.utils.Const;

/**
 * 表格列表头部对象
 * 
 * @author 潘巍（Peter Pan）
 * @since 2011-5-13 上午07:45:41
 */
public class DataTableHeaderObject {

	// 名称
	private String label;

	// 描述
	private String description;

	// 是否允许排序
	private boolean sortable = false;

	// 是否要筛选
	private boolean filterable = false;

	// 列宽
	private Integer width;

	private Float widthF;

	// 是否可以调整宽度
	private boolean enableChangeSize = true;

	// 对齐类型
	private DataTableCellAlignType alignType;

	private boolean display = true;

	public DataTableHeaderObject(String label) {
		this.label = label;
	}

	public String getLabel() {
		return label;
	}

	public DataTableHeaderObject setLabel(String label) {
		this.label = label;
		return this;
	}

	public String getDescription() {
		return description;
	}

	public DataTableHeaderObject setDescription(String description) {
		this.description = description;
		return this;
	}

	public boolean isSortable() {
		return sortable;
	}

	public DataTableHeaderObject setSortable(boolean sortable) {
		this.sortable = sortable;
		return this;
	}

	public boolean isFilterable() {
		return filterable;
	}

	public DataTableHeaderObject setFilterable(boolean filterable) {
		this.filterable = filterable;
		return this;
	}

	public String getWidth() {
		if (this.width != null) {
			return this.width + "px";
		}
		if (this.widthF != null) {
			if (this.widthF > 0 && this.widthF <= 1) {
				return ((int) (this.widthF * 100)) + "%";
			}
		}
		return Const.DEFAULT_COLUMN_WIDTH + "px";
	}

	public DataTableHeaderObject setWidth(Integer width) {
		this.width = width;
		return this;
	}

	public DataTableHeaderObject setWidth(Float width) {
		this.widthF = width;
		return this;
	}

	public boolean isEnableChangeSize() {
		return enableChangeSize;
	}

	public DataTableHeaderObject setEnableChangeSize(boolean enableChangeSize) {
		this.enableChangeSize = enableChangeSize;
		return this;
	}

	public DataTableCellAlignType getAlignType() {
		if (alignType == null) {
			return DataTableCellAlignType.CENTER;
		}
		return alignType;
	}

	public String getAlignStyle() {
		return getAlignType().getStyle();
	}

	public DataTableHeaderObject setAlignType(DataTableCellAlignType alignType) {
		this.alignType = alignType;
		return this;
	}

	public boolean isDisplay() {
		return display;
	}

	public DataTableHeaderObject setDisplay(boolean display) {
		this.display = display;
		return this;
	}

}
